"""
Event type string used in BQ for redis.pubsub channel.
"""

from enum import Enum
from typing import Callable, Any

# region event type
EVENT_RQ = "rq_"  # 查询请求，可与其它联合使用：EVENT_RQ+EVENT_ORDER 生成 rq_eOrder.
EVENT_TIMER = "eTimer"  # noqa
INSTRUMENT = "inst."
FUTURE = "future."
OPTION = "option."
ORDER = "order."
PARKORDER = "park_order."
TRADE = "trade."
ACCOUNT = "acc."
POSITION = "position."
POSITIONDETAIL = "position_detail."
STRATEGY = "strategy."
STRASIGNAL = "eStraSignal."
TICK = "Tick."  # 后加 instrument id, publish 时的 channel
BAR = "Bar."

SUBSCRIBEINSTRUMENT = "Subscribe."
REQSUBINST = "ReqSubInst."
REQORDERINSERT = "ReqOrderInsert."
REQUNSUBINST = "ReqUnSubInst."
RQACC = "ReqQryAccount."
RQTRADE = "ReqQryTrade."
RQORDER = "ReqQryOrder."
RQPOSITION = "ReqQryPosition."
RQPOSITIONDETAIL = "ReqQryPositionDetail."

# # PUBLISH<=>SUBSCRIBE 用作channel
CTPWORK = "CTPWORK"  # msg:StartQuote,StopQuote,StartTrade,StopTrade
EVENT_MD_CONNECT_STATUS = "QuoteConnected"  # true or false  1 or 0
EVENT_MD_LOGIN_STATUS = "QuoteLogin"  # true or false
EVENT_TD_CONNECT_STATUS = "TradeConnected"
EVENT_TD_LOGIN_STATUS = "TradeLogin"

EVENT_TICK = "eTick."
EVENT_TRADE = "eTrade."
EVENT_ORDER = "eOrder."
EVENT_PARK_ORDER = "eParkOrder."
EVENT_POSITION = "ePosition."
EVENT_ACCOUNT = "eAccount."
EVENT_CONTRACT = "eContract."
EVENT_LOG = "eLog"
EVENT_POSITION_DETAIL = "ePositionDetail."
EVENT_MD_LOGIN = "eMDLogin."
EVENT_TD_LOGIN = "eTDLogin."
EVENT_MD_CONNECTED = "eMDConnected."
EVENT_TD_CONNECTED = "eTDConnected."
EVENT_INSTRUMENT = "eInstrument."
EVENT_INSTRUMENT_OK = "eInstrumentOK."
EVENT_POSITION_DETAIL_OK = "ePositionDetailOK."
EVENT_POSITION_OK = "ePositionOK."
EVENT_INSTRUMENT_STATUS = "eInstrumentStatus."
EVENT_ACCOUNT_OK = "eAccountOK."
EVENT_ORDER_OK = "eOrderOK."
EVENT_FUTURE = "eFuture."
EVENT_STRA = "eStrategy."
EVENT_STRATEGY = "eStrategy."
EVENT_STRA_SIGNAL = "eStraSignal."
EVENT_STRATEGY_SIGNAL = "eStraSignal."
EVENT_STRATEGY_HISTORY_SIGNALS = "eStraHistSgls."
EVENT_STOP_ORDER = "eStopOrder."
EVENT_SUBSCRIBE = "eSubscribe."
EVENT_UNSUBSCRIBE = "eUnSubscribe."

EVENT_REQ_SUBSCRIBE = "eReqSubscribe."
EVENT_REQ_SUBSCRIBE_TICK = "eReqSubscribeTick."
EVENT_REQ_SUBSCRIBE_TICKS = "eReqSubscribeTicks."
EVENT_REQ_SUBSCRIBE_BAR = "eReqSubscribeBar."
EVENT_REQ_SUBSCRIBE_BARS = "eReqSubscribeBars."
EVENT_REQ_PARAMS = 'eReqParams.'

EVENT_ON_TICK = "eOnTick."
EVENT_ON_TICKS = "eOnTicks."
EVENT_ON_BAR = "eOnBar."
EVENT_ON_BARS = "eOnBars."
EVENT_ON_PARAMS = "eOnParams."


# endregion event type


class Event:
    """
    Event object consists of a type string which is used
    by event engine for distributing event, and a data
    object which contains the real data.
    """

    def __init__(self, event_type: str, data: Any = None):
        """"""
        self.event_type: str = event_type
        self.data: Any = data


# Defines handler function to be used in event engine.
HandlerType = Callable[[Event], None]


class EventType(Enum):
    EVENT_RQ = "rq_"  # 查询请求，可与其它联合使用：EVENT_RQ+EVENT_ORDER 生成 rq_eOrder.
    EVENT_TIMER = "eTimer"  # noqa
    INSTRUMENT = "inst."
    FUTURE = "future."
    OPTION = "option."
    ORDER = "order."
    PARKORDER = "park_order."
    TRADE = "trade."
    ACCOUNT = "acc."
    POSITION = "position."
    POSITIONDETAIL = "position_detail."
    STRATEGY = "strategy."
    STRASIGNAL = "eStraSignal."
    TICK = "Tick."  # 后加 instrument id, publish 时的 channel
    BAR = "Bar."

    SUBSCRIBEINSTRUMENT = "Subscribe."
    REQSUBINST = "ReqSubInst."
    REQORDERINSERT = "ReqOrderInsert."
    REQUNSUBINST = "ReqUnSubInst."
    RQACC = "ReqQryAccount."
    RQTRADE = "ReqQryTrade."
    RQORDER = "ReqQryOrder."
    RQPOSITION = "ReqQryPosition."
    RQPOSITIONDETAIL = "ReqQryPositionDetail."

    # # PUBLISH<=>SUBSCRIBE 用作channel
    CTPWORK = "CTPWORK"  # msg:StartQuote,StopQuote,StartTrade,StopTrade
    EVENT_MD_CONNECT_STATUS = "QuoteConnected"  # true or false  1 or 0
    EVENT_MD_LOGIN_STATUS = "QuoteLogin"  # true or false
    EVENT_TD_CONNECT_STATUS = "TradeConnected"
    EVENT_TD_LOGIN_STATUS = "TradeLogin"

    EVENT_TICK = "eTick."
    EVENT_TRADE = "eTrade."
    EVENT_ORDER = "eOrder."
    EVENT_PARK_ORDER = "eParkOrder."
    EVENT_POSITION = "ePosition."
    EVENT_ACCOUNT = "eAccount."
    EVENT_CONTRACT = "eContract."
    EVENT_LOG = "eLog"
    EVENT_POSITION_DETAIL = "ePositionDetail."
    EVENT_MD_LOGIN = "eMDLogin."
    EVENT_TD_LOGIN = "eTDLogin."
    EVENT_MD_CONNECTED = "eMDConnected."
    EVENT_TD_CONNECTED = "eTDConnected."
    EVENT_INSTRUMENT = "eInstrument."
    EVENT_INSTRUMENT_OK = "eInstrumentOK."
    EVENT_POSITION_DETAIL_OK = "ePositionDetailOK."
    EVENT_POSITION_OK = "ePositionOK."
    EVENT_INSTRUMENT_STATUS = "eInstrumentStatus."
    EVENT_ACCOUNT_OK = "eAccountOK."
    EVENT_ORDER_OK = "eOrderOK."
    EVENT_FUTURE = "eFuture."
    EVENT_STRA = "eStrategy."
    EVENT_STRATEGY = "eStrategy."
    EVENT_STRA_SIGNAL = "eStraSignal."
    EVENT_STRATEGY_SIGNAL = "eStraSignal."
    EVENT_STRATEGY_HISTORY_SIGNALS = "eStraHistSgls."
    EVENT_STOP_ORDER = "eStopOrder."
    EVENT_SUBSCRIBE = "eSubscribe."
    EVENT_UNSUBSCRIBE = "eUnSubscribe."

    EVENT_REQ_SUBSCRIBE = "eReqSubscribe."
    EVENT_REQ_SUBSCRIBE_TICK = "eReqSubscribeTick."
    EVENT_REQ_SUBSCRIBE_TICKS = "eReqSubscribeTicks."
    EVENT_REQ_SUBSCRIBE_BAR = "eReqSubscribeBar."
    EVENT_REQ_SUBSCRIBE_BARS = "eReqSubscribeBars."
    EVENT_REQ_PARAMS = 'eReqParams.'

    EVENT_ON_TICK = "eOnTick."
    EVENT_ON_TICKS = "eOnTicks."
    EVENT_ON_BAR = "eOnBar."
    EVENT_ON_BARS = "eOnBars."
    EVENT_ON_PARAMS = "eOnParams."


if __name__ == "__main__":

    for itm in EventType:
        print(itm.name, itm.value)
